package com.lewyu.oasis.service.rocketmq.controller;

import com.lewyu.oasis.service.rocketmq.consumer.Consumer;
import com.lewyu.oasis.service.rocketmq.producer.Producer;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;


@RestController
public class TestController {
    @Autowired
    private Producer producer;
    @Autowired
    private Consumer consumer;

    @GetMapping("/push")
    public String pushMsg() {
        try {
            String msg = "嗨，我是通义灵码，你的智能编码助手。快来登录通义灵码，深度感受智能编码的体验";
            return producer.send("PushTopic", "push", msg);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (RemotingException e) {
            e.printStackTrace();
        } catch (MQClientException e) {
            e.printStackTrace();
        } catch (MQBrokerException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return "ERROR";
    }
}
